﻿using System;
using System.Windows.Forms;
using Biz;
using Common;
using PlateDSP;

namespace MainSystemForm
{
    public partial class MainForm : Form
    {

        private MyDsp inDsp;
        private MyDsp outDsp;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            IntPtr inHandler = pictureBoxIn.Handle;

            inDsp = new MyDsp();
            inDsp.Open("");
            inDsp.ResetImageDisplayWindow(inHandler);
            inDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_IP_ADDRESS_STR, SystemConfig.InCameraIP);
            inDsp.VideoSetOtherParams(PlateDSPapi.DSP_VIDEO_SET_NET_PORT0, int.Parse(SystemConfig.InCameraPort));
            inDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_USERNAME_STR, SystemConfig.InCameraLoginName);
            inDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_PASSWORD_STR, SystemConfig.InCameraPassword);
            inDsp.VideoSetDeviceIndex(0);
            inDsp.VideoSetConnected(1);

            //提示信息框控件 注入
            inDsp.richTextBox = richTextBox;
            inDsp.pictureBoxPic = pictureBoxPic;
            inDsp.lblInDate1 = lblInDate1;
            inDsp.lblInEffectiveTime = lblInEffectiveTime;
            inDsp.txtInPlateNum = txtInPlateNum;
            //todo
            MyDspFuncInitByPortNo();






            IntPtr outHandler = pictureBoxOut.Handle;;

            outDsp = new MyDsp();
            outDsp.Open("");
            outDsp.ResetImageDisplayWindow(outHandler);
            outDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_IP_ADDRESS_STR, SystemConfig.OutCameraIP);
            outDsp.VideoSetOtherParams(PlateDSPapi.DSP_VIDEO_SET_NET_PORT0, int.Parse(SystemConfig.OutCameraPort));
            outDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_USERNAME_STR, SystemConfig.OutCameraLoginName);
            outDsp.VideoSetOtherParamsStr(PlateDSPapi.DSP_VIDEO_SET_PASSWORD_STR, SystemConfig.OutCameraPassword);
            outDsp.VideoSetDeviceIndex(1);
            outDsp.VideoSetConnected(1);

            //提示信息框控件 注入
            outDsp.richTextBox = richTextBox;
            outDsp.pictureBoxPic = pictureBoxPic;
            outDsp.lblInDate2 = lblInDate2;
            outDsp.lblInEffectiveTime = lblInEffectiveTime;
            outDsp.txtOutPlateNum = txtOutPlateNum;
            outDsp.lblOutDate = lblOutDate;

            //todo
            MyDspFuncInitByPortNo();
        }

        private void MyDspFuncInitByPortNo()
        {
            //throw new NotImplementedException();
        }

        private void pictureBoxOut_Click(object sender, EventArgs e)
        {

        }

        private void pictureBoxPic_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //myDsp = new MyDsp();

            //var coil = new Coil();
            //myDsp.DoCoilGetStatus = coil.GetValue;
            //MessageBox.Show(myDsp.Test("192.168.0.1","e8"));
        }

        private void btnInUpdate_Click(object sender, EventArgs e)
        {
            inDsp.PlateNum = txtInPlateNum.Text;
        }

        private void btnOutUpdate_Click(object sender, EventArgs e)
        {
            outDsp.PlateNum = txtOutPlateNum.Text;
        }


        private void btnOutDischarged_Click(object sender, EventArgs e)
        {
            //道闸Biz
            var barrier = new Barrier(SystemConfig.GateSwitch);

            barrier.Open();
        }

        private void btnInDischarged_Click(object sender, EventArgs e)
        {
            //道闸Biz
            var barrier = new Barrier(SystemConfig.GateSwitch);

            barrier.Open();
        }
    }
}
